home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
keybd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
3KB
|
83 lines
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/* sample program to demonstrate direct communications with the keyboard,
* won't work unless input device is disabled, so that keyboard can
* be accessed individually
*
* Author: Rob Peck 10/11/85
*/
#include <exec/types.h>
#include <exec/io.h>
#include <devices/keyboard.h>
#include <devices/inputevent.h>
extern struct Port *CreatePort();
extern struct IOStdReq *CreateStdIO();
SHORT error;
struct IOStdReq *keyreq;
struct Port *keyport;
struct InputEvent *keydata; /* pointer into the returned data area
where an input event has been sent */
BYTE keybuffer[sizeof( struct InputEvent )];
main()
{
keyport = CreatePort(0,0);
if(keyport == 0) { printf("\nError during CreatePort");
exit(-1);
}
keyreq = CreateStdIO(keyport);
/* make an io request block for
* communicating with the keyboard */
if(keyreq == 0) { printf("\nError during CreateStdIO");
DeletePort(keyport);
exit(-2);
}
error = OpenDevice("keyboard.device",0,keyreq,0);
/* open the device for access */
if (error != 0) { printf("\nCan't open keyboard!");
ReturnMemoryToSystem();
exit(-100);
}
keyreq->io_Length = sizeof(struct InputEvent);
/* read one event each time we go back to the keyboard */
keyreq->io_Data = keybuffer;
/* show where to put the data when read */
keydata = (struct InputEvent *)keybuffer;
keyreq->io_Command = KBD_READEVENT; /* get an event!! */
for(;;) /* FOREVER */
{
printf("\n Ready to retrieve another key\n");
DoIO( keyreq );
printf("\n Raw key found this time was %lx",keydata->ie_Code);
}
ReturnMemoryToSystem(); /* can't get here because of FOREVER,
* but if user provides an exit..... */
}
ReturnMemoryToSystem()
{
DeleteStdIO(keyreq);
DeletePort(keyport);
return;
}